using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using Newtonsoft.Json;

namespace LabMS.Web.Vote
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Insert : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                HttpRequest request = context.Request;

                // string s = System.Web.HttpContext.Current.Server.UrlEncode("http://h.com/+");

                string strJSON = System.Web.HttpContext.Current.Server.UrlDecode(request.Form.ToString());

                LabMS.Model.VoteJson voteJson = (LabMS.Model.VoteJson)Newtonsoft.Json.JavaScriptConvert.DeserializeObject(strJSON, typeof(LabMS.Model.VoteJson));

                #region Insert

                ExtendBLL.Vote vote = new ExtendBLL.Vote();
                vote.Insert(voteJson);

                #endregion

                context.Response.ContentType = "application/json";
                context.Response.Write("{success: true}");
            }
            catch (Exception ex)
            {
                context.Response.ContentType = "application/json";
                context.Response.Write("{success: false, msg: '" + ex.Message + "'}");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
